package ltd.newbee.mall.entity;

import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Data;
import org.hibernate.Hibernate;
import org.hibernate.annotations.CreationTimestamp;
import org.hibernate.annotations.DynamicUpdate;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;

import javax.persistence.Entity;
import javax.persistence.EntityListeners;
import javax.persistence.Id;
import java.math.BigDecimal;
import java.util.Date;
import java.util.Objects;

/**
 * @ClassName: PurchaseInfo
 * @Description: 进货记录
 * @Author: bwh
 * @Date: 2022/9/4 7:16
 * @Version 1.0
 */
@Data
@Entity
@DynamicUpdate //自动更新时间
public class NewbeeMallPurchaseInfo {
    /**
     * 采购单据ID
     */
    @Id
    private String purchaseId;

    /**
     * 供货商ID
     */
    private String supplierId;

    /**
     * 商品ID
     */
    private long goodsId;

    /**
     * 商品名称
     */
    private String goodsName;

    /**
     * 采购商品数量
     */
    private Integer purchaseQuantity;

    /**
     * 进货价
     */
    private BigDecimal importPrice;

    /**
     * 采购员工ID
     */
    private String staffId;


    /**
     * 采购日期
     */
    @CreationTimestamp
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    private Date purchaseDate;

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || Hibernate.getClass(this) != Hibernate.getClass(o)) return false;
        NewbeeMallPurchaseInfo that = (NewbeeMallPurchaseInfo) o;
        return purchaseId != null && Objects.equals(purchaseId, that.purchaseId);
    }

    @Override
    public int hashCode() {
        return getClass().hashCode();
    }
}
